package stream;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

public class operator_connect {
    public static void main(String[] args) throws Exception {
    //   创建流式数据环
        StreamExecutionEnvironment env =  StreamExecutionEnvironment.getExecutionEnvironment();
    //    添加数据源
        DataStreamSource<Long> source1 = env.addSource(new oneparalleSource());
        DataStream<String> source2 = env.addSource(new oneparalleSource()).map(new MapFunction<Long, String>() {
            public String map(Long aLong) throws Exception {
                return "String" + aLong;
            }
        });

        ConnectedStreams<Long,String> source3 = source1.connect(source2);

        source3.map(new CoMapFunction<Long, String, Object>() {
            public Object map1(Long aLong) throws Exception {
                return "long + 1 操作" + (aLong);
            }

            public Object map2(String s) throws Exception {
                return "String + 1 操作" + s ;
            }
        }).print();

        //result.print().setParallelism(2);
        env.execute("operator_union");
    }
}

